package com.fantabest.console.client;

import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.fantabest.common.client.AppEvents;
import com.fantabest.common.entity.Manager;
import com.fantabest.console.client.mvc.ConsoleController;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

public class FantaBestConsole implements EntryPoint {

	public void onModuleLoad() {

		// Aggiungo i controller al dispatcher
		Dispatcher dispatcher = Dispatcher.get();
		dispatcher.addController(new ConsoleController());

		if (GWT.getHostPageBaseURL().contains("localhost")) {
			BeanModelFactory factory = BeanModelLookup.get().getFactory(
					Manager.class);
			Manager manager = new Manager("Alberto", "Giantin", "Giant",
					"albertogiantin@gmail.com", "12345");
			manager.setAdmin(true);
			BeanModel beanModel = factory.createModel(manager);
			dispatcher.dispatch(AppEvents.Login, beanModel);
		} else {
			dispatcher.dispatch(AppEvents.Init);
		}

	}

}
